package com.ruoyi.patrol.controller;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.patrol.domain.PtLineTask;
import com.ruoyi.patrol.service.IPtLineTaskService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 长期排班定时任务Controller
 *
 * @author Du
 * @date 2023-11-28
 */
@RestController
@RequestMapping("/patrol/lineTask")
public class PtLineTaskController extends BaseController {
    @Autowired
    private IPtLineTaskService ptLineTaskService;

    /**
     * 查询长期排班定时任务列表
     */
    @PreAuthorize("@ss.hasPermi('patrol:lineTask:list')")
    @GetMapping("/list")
    public TableDataInfo list(PtLineTask ptLineTask) {
        startPage();
        ptLineTask.setSchoolId(SecurityUtils.getSchoolId());
        List<PtLineTask> list = ptLineTaskService.selectPtLineTaskList(ptLineTask);
        return getDataTable(list);
    }

    /**
     * 导出长期排班定时任务列表
     */
    @PreAuthorize("@ss.hasPermi('patrol:lineTask:export')")
    @Log(title = "长期排班定时任务", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PtLineTask ptLineTask) {
        List<PtLineTask> list = ptLineTaskService.selectPtLineTaskList(ptLineTask);
        ExcelUtil<PtLineTask> util = new ExcelUtil<PtLineTask>(PtLineTask.class);
        return util.exportExcel(list, "lineTask");
    }

    /**
     * 获取长期排班定时任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('patrol:lineTask:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(ptLineTaskService.selectPtLineTaskById(id));
    }

    /**
     * 新增长期排班定时任务
     */
    @PreAuthorize("@ss.hasPermi('patrol:lineTask:add')")
    @Log(title = "长期排班定时任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PtLineTask ptLineTask) {
        return toAjax(ptLineTaskService.insertPtLineTask(ptLineTask));
    }

    /**
     * 修改长期排班定时任务
     */
    @PreAuthorize("@ss.hasPermi('patrol:lineTask:edit')")
    @Log(title = "长期排班定时任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PtLineTask ptLineTask) {
        return toAjax(ptLineTaskService.updatePtLineTask(ptLineTask));
    }

    /**
     * 删除长期排班定时任务
     */
    @PreAuthorize("@ss.hasPermi('patrol:lineTask:remove')")
    @Log(title = "长期排班定时任务", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(ptLineTaskService.deletePtLineTaskByIds(ids));
    }
}
